/*
**  Copyright (c) 2014 Michael Liu(michael.liu.point@gmail.com).
**
**  Project: Gateway Unified Management Platform
**  File:    mtk7620_if.c
**  Author:  Michael
**  Date:    03/20/2014
**
**  Purpose:
**    mtk7620 interface management implement.
*/

/* Include files. */

#include "mtk7620_local.h"

/* Macro constant definitions. */

#define OS_DEP_BONDING_DRIVER_MOD	"/lib/modules/2.6.36/kernel/drivers/net/bonding/bonding.ko"

#define SYS_FS_BONDING_MASTER		"/sys/class/net/bonding_masters"
#define SYS_FS_APCLI_BOND_MODE		"/sys/class/net/apcli_bond/bonding/mode"
#define SYS_FS_APCLI_BOND_MIIMON	"/sys/class/net/apcli_bond/bonding/miimon"
#define SYS_FS_APCLI_BOND_SLAVE		"/sys/class/net/apcli_bond/bonding/slaves"

/* Type definitions. */

/* Local function declarations. */

/* Macro API definitions. */

#define dp_if_set_base_on_led(dp_if, led_dev) \
do {																		\
	(dp_if)->led.led = (led_dev);											\
	(dp_if)->led.status = eLED_STATUS_SIGNAL_NONE;							\
	(dp_if)->led.counter = 0;												\
} while (0)

/* Global variable declarations. */

extern tdp_dev raeth;
extern tdp_dev rt2860v2_ap;
extern tdp_dev rlt_wifi;
extern tsa_dev rt_led;

static tdp_if lan_bridge = {
	/* .name = */ "lan",
	/* .type = */ eDP_IF_TYPE_BRIDGE,
	/* .cls = */ eDP_IF_CLASS_IF_BASED,
	/* .attr = */ bit_to_mask(eDP_IF_ATTR_LINK) | bit_to_mask(eDP_IF_ATTR_NET),
	/* .prepare = */ eBOOL_FALSE,
	/* .based_on_dev = */ NULL,
};

static tdp_if eth2 = {
	/* .name = */ "eth2",
	/* .type = */ eDP_IF_TYPE_ETH,
	/* .cls = */ eDP_IF_CLASS_DEV_BASED,
	/* .attr = */ bit_to_mask(eDP_IF_ATTR_LINK) | bit_to_mask(eDP_IF_ATTR_NET),
	/* .prepare = */ eBOOL_FALSE,
	/* .based_on_dev = */ &raeth,
};

static tdp_if eth2_vid1 = {
	/* .name = */ "eth2.1",
	/* .type = */ eDP_IF_TYPE_VLAN,
	/* .cls = */ eDP_IF_CLASS_IF_BASED,
	/* .attr = */ bit_to_mask(eDP_IF_ATTR_LINK) | bit_to_mask(eDP_IF_ATTR_NET),
	/* .prepare = */ eBOOL_FALSE,
	/* .based_on_dev = */ &raeth,
};

static tdp_if eth2_vid2 = {
	/* .name = */ "eth2.2",
	/* .type = */ eDP_IF_TYPE_VLAN,
	/* .cls = */ eDP_IF_CLASS_IF_BASED,
	/* .attr = */ bit_to_mask(eDP_IF_ATTR_LINK) | bit_to_mask(eDP_IF_ATTR_NET),
	/* .prepare = */ eBOOL_FALSE,
	/* .based_on_dev = */ &raeth,
};

#ifdef APCLI_BOND_SUPPORT
static tdp_if apcli_bond = {
	/* .name = */ "apcli_bond",
	/* .type = */ eDP_IF_TYPE_BONDING,
	/* .cls = */ eDP_IF_CLASS_IF_BASED,
	/* .attr = */ bit_to_mask(eDP_IF_ATTR_LINK) | bit_to_mask(eDP_IF_ATTR_NET),
	/* .prepare = */ eBOOL_FALSE,
	/* .based_on_dev = */ NULL,
};
#endif /* APCLI_BOND_SUPPORT */

static tdp_if wlan24g_ap = {
	/* .name = */ "ra0",
	/* .type = */ eDP_IF_TYPE_WLAN24G_AP,
	/* .cls = */ eDP_IF_CLASS_DEV_BASED,
	/* .attr = */ bit_to_mask(eDP_IF_ATTR_LINK) | bit_to_mask(eDP_IF_ATTR_NET),
	/* .prepare = */ eBOOL_FALSE,
	/* .based_on_dev = */ &rt2860v2_ap,
};

static tdp_if wlan5g_ap = {
	/* .name = */ "rai0",
	/* .type = */ eDP_IF_TYPE_WLAN5G_AP,
	/* .cls = */ eDP_IF_CLASS_DEV_BASED,
	/* .attr = */ bit_to_mask(eDP_IF_ATTR_LINK) | bit_to_mask(eDP_IF_ATTR_NET),
	/* .prepare = */ eBOOL_FALSE,
	/* .based_on_dev = */ &rlt_wifi,
};

static tdp_if wlan24g_cli = {
	/* .name = */ "apcli0",
	/* .type = */ eDP_IF_TYPE_WLAN24G_CLI,
	/* .cls = */ eDP_IF_CLASS_DEV_BASED,
	/* .attr = */ bit_to_mask(eDP_IF_ATTR_LINK) | bit_to_mask(eDP_IF_ATTR_NET),
	/* .prepare = */ eBOOL_FALSE,
	/* .based_on_dev = */ &rt2860v2_ap,
};

static tdp_if wlan5g_cli = {
	/* .name = */ "apclii0",
	/* .type = */ eDP_IF_TYPE_WLAN5G_CLI,
	/* .cls = */ eDP_IF_CLASS_DEV_BASED,
	/* .attr = */ bit_to_mask(eDP_IF_ATTR_LINK) | bit_to_mask(eDP_IF_ATTR_NET),
	/* .prepare = */ eBOOL_FALSE,
	/* .based_on_dev = */ &rlt_wifi,
};

static inline void init_dp_if_list(tdata_paths * dp, tdp_if * dp_if, unsigned int dp_idx)
{

	INIT_LIST_HEAD(&dp_if->all_list);
	INIT_LIST_HEAD(&dp_if->hierarchy);
	INIT_LIST_HEAD(&dp_if->based_on_if);
	list_add(&dp_if->all_list, &dp->all_ifs);
	dp_if->dp_idx = dp_idx;
	list_add(&dp_if->hierarchy, &dp->net_ifs[dp_idx]);
}

void prepare_wlan_wps_cfg(void)
{

	const char *val;
	char pin_val[16];
	unsigned int pin;

	val = pf_dep_cfg_get_val(RT2860_NVRAM, WLAN_WSC_VENDOR_PIN_CODE, "");
	if (val[0] == '\0') {
		pf_dep_wlan_set_wsc_gen_pin_code(&pin);
		sprintf(pin_val, "%u", pin);
		pf_dep_cfg_set_val(RT2860_NVRAM, WLAN_WSC_VENDOR_PIN_CODE, pin_val);
		pf_dep_cfg_set_val(RTDEV_NVRAM, WLAN_WSC_VENDOR_PIN_CODE, pin_val);
	}

}

e_ret init_wlan24g_ap_if(tdata_paths * dp)
{
	int i;
	e_ret ret;
	tmask mask;
	const char *val;
	const char *append_val;
	char *item, *item_p, acl_str[1024];
	twlan_ap_if_linkcfg linkcfg;

	memset(&linkcfg, 0, sizeof(linkcfg));
	memset(&mask, 0, sizeof(mask));

	/* Set LOAD CONFIG BIT */
	mask_set_bit(mask.mask[7], eDP_IF_LINKCFG_MASK7_LOAD_CFG);

	val = pf_dep_cfg_get_val(RT2860_NVRAM, WLAN_AP1_SSID_KEY, DEFAULT_WLAN_24G_AP_SSID);
	str_safe_cpy(linkcfg.ssid, val, WLAN_SSID_SIZE - 1);
	mask_set_bit(mask.mask[0], eWLAN_AP_IF_LINKCFG_MASK0_SSID);

	val = pf_dep_cfg_get_val(RT2860_NVRAM, WLAN_AP_WL_MODE_KEY, DEFAULT_WLAN_24G_AP_WL_MODE);
	linkcfg.mode = pd_dep_wlmode_to_wlmode_24g(val);

	val = pf_dep_cfg_get_val(RT2860_NVRAM, WLAN_AP_HTBW_CFG_KEY, DEFAULT_WLAN_24G_AP_HTBW);
	append_val = pf_dep_cfg_get_val(RT2860_NVRAM, WLAN_AP_VHTBW_CFG_KEY, DEFAULT_WLAN_24G_AP_VHTBW);
	linkcfg.bw = pd_dep_bw_to_bw(val, append_val);

	val = pf_dep_cfg_get_val(RT2860_NVRAM, WLAN_AP_SGI_CFG_KEY, DEFAULT_WLAN_24G_AP_HTGI);
	linkcfg.sgi = (val[0] == '1') ? eBOOL_TRUE : eBOOL_FALSE;

	val = pf_dep_cfg_get_val(RT2860_NVRAM, WLAN_AP_TXPOWER_KEY, DEFAULT_WLAN_24G_AP_TXPOWER);
	linkcfg.tx_pwr = strtol(val, NULL, 10);

	val = pf_dep_cfg_get_val(RT2860_NVRAM, WLAN_AP_CHANNEL_KEY, DEFAULT_WLAN_24G_AP_CHANNEL);
	append_val = pf_dep_cfg_get_val(RT2860_NVRAM, WLAN_AP_AUTO_CH_SEL_KEY, DEFAULT_WLAN_24G_AP_AUTO_CHANNEL);
	if ((val[0] == '0') || (append_val[0] == '1')) {
		linkcfg.channel = 0;
	} else {
		linkcfg.channel = strtol(val, NULL, 10);
	}

	val = pf_dep_cfg_get_val(RT2860_NVRAM, WLAN_AP_BEACON_PERIOD_KEY, DEFAULT_WLAN_24G_AP_BEACON_PERIOD);
	linkcfg.beacon_interval = strtol(val, NULL, 10);

	val = pf_dep_cfg_get_val(RT2860_NVRAM, WLAN_AP_HIDE_SSID_KEY, DEFAULT_WLAN_24G_AP_HIDE_SSID);
	linkcfg.hide_ssid = (val[0] == '1') ? eBOOL_TRUE : eBOOL_FALSE;

	val = pf_dep_cfg_get_val(RT2860_NVRAM, WLAN_AP_STA_ISOLATE_KEY, DEFAULT_WLAN_24G_AP_STA_ISOLATE);
	linkcfg.sta_isolate = (val[0] == '1') ? eBOOL_TRUE : eBOOL_FALSE;;

	val = pf_dep_cfg_get_val(RT2860_NVRAM, WLAN_AP_AUTH_MODE_KEY, DEFAULT_WLAN_24G_AP_AUTH_MODE);
	append_val = pf_dep_cfg_get_val(RT2860_NVRAM, WLAN_AP_ENC_WPA_MIX_KEY, DEFAULT_WLAN_24G_AP_ENC_WPAMIX);
	if (append_val[0] != '\0') {
		linkcfg.auth_mode = eWLAN_AUTH_MODE_WPAPSKWPA2PSK;
	} else {
		linkcfg.auth_mode = pd_dep_authmode_to_authmode(val);
	}

	val = pf_dep_cfg_get_val(RT2860_NVRAM, WLAN_AP_ENC_TYPE_KEY, DEFAULT_WLAN_24G_AP_ENC_TYPE);
	append_val = pf_dep_cfg_get_val(RT2860_NVRAM, WLAN_AP_ENC_WPA_MIX_KEY, DEFAULT_WLAN_24G_AP_ENC_WPAMIX);
	linkcfg.enc_method = pd_dep_enctype_to_enctype(linkcfg.auth_mode, val, append_val);;

	if (linkcfg.enc_method == eWLAN_ENC_METHOD_NONE) {
		linkcfg.sec_key.wpa_psk[0] = 0;
	} else if (linkcfg.enc_method == eWLAN_ENC_METHOD_WEP) {
		/* Read WEP Key. */
		val = pf_dep_cfg_get_val(RT2860_NVRAM, WLAN_AP1_ENC_WEP_KEY1_STR_KEY, DEFAULT_WLAN_24G_AP_KEY_STR);
		str_safe_cpy(linkcfg.sec_key.wep_key.key[0].value, val, WLAN_ENC_WEP_KEY_MAX_SIZE - 1);

		val = pf_dep_cfg_get_val(RT2860_NVRAM, WLAN_AP1_ENC_WEP_KEY2_STR_KEY, DEFAULT_WLAN_24G_AP_KEY_STR);
		str_safe_cpy(linkcfg.sec_key.wep_key.key[1].value, val, WLAN_ENC_WEP_KEY_MAX_SIZE - 1);

		val = pf_dep_cfg_get_val(RT2860_NVRAM, WLAN_AP1_ENC_WEP_KEY3_STR_KEY, DEFAULT_WLAN_24G_AP_KEY_STR);
		str_safe_cpy(linkcfg.sec_key.wep_key.key[2].value, val, WLAN_ENC_WEP_KEY_MAX_SIZE - 1);

		val = pf_dep_cfg_get_val(RT2860_NVRAM, WLAN_AP1_ENC_WEP_KEY4_STR_KEY, DEFAULT_WLAN_24G_AP_KEY_STR);
		str_safe_cpy(linkcfg.sec_key.wep_key.key[3].value, val, WLAN_ENC_WEP_KEY_MAX_SIZE - 1);

		val = pf_dep_cfg_get_val(RT2860_NVRAM, WLAN_AP_ENC_WEP_DEFAULT_KEY_ID_KEY, DEFAULT_WLAN_24G_AP_KEY_ID);
		linkcfg.sec_key.wep_key.default_id = strtol(val, NULL, 10);
		if ((linkcfg.sec_key.wep_key.default_id == 0) || (linkcfg.sec_key.wep_key.default_id > 4)) {
			linkcfg.sec_key.wep_key.default_id = 1;
		}
	} else {
		/* Read WPA PSK. */
		val = pf_dep_cfg_get_val(RT2860_NVRAM, WLAN_AP1_ENC_WPAPSK_KEY, DEFAULT_WLAN_24G_AP_WPAPSK);
		str_safe_cpy(linkcfg.sec_key.wpa_psk, val, WLAN_ENC_WPA_PSK_MAX_SIZE - 1);
	}

	val = pf_dep_cfg_get_val(RT2860_NVRAM, WLAN_AP1_ACCESS_POLICY_KEY, DEFAULT_WLAN_24G_AP_ACL_TYPE);
	linkcfg.acl.acl_type = strtol(val, NULL, 10);

	val = pf_dep_cfg_get_val(RT2860_NVRAM, WLAN_AP1_ACL_STRING_KEY, DEFAULT_WLAN_24G_AP_ACL_STR);
	strcpy(acl_str, val);
	item = strtok_r(acl_str, ";", &item_p);
	i = 0;
	while (item != NULL) {
		strcpy(linkcfg.acl.acl[i++].mac, item);
		item = strtok_r(NULL, ";", &item_p);
	}
	linkcfg.acl.counter = i;

	val = pf_dep_cfg_get_val(RT2860_NVRAM, WLAN_AP_APSD_CAPABLE, DEFAULT_WLAN_24G_AP_APSD_CAPABLE);
	linkcfg.wmm_apsd = (val[0] == '1') ? eBOOL_TRUE : eBOOL_FALSE;
	val = pf_dep_cfg_get_val(RT2860_NVRAM, WLAN_AP_DLS_CAPABLE, DEFAULT_WLAN_24G_AP_DLS_CAPABLE);
	linkcfg.wmm_dls = (val[0] == '1') ? eBOOL_TRUE : eBOOL_FALSE;

	val = pf_dep_cfg_get_val(RT2860_NVRAM, WLAN_AP_BG_PROTECTION, DEFAULT_WLAN_24G_AP_BG_PROTECTION);
	linkcfg.bg_protection = pd_dep_bgprotect_to_bgprotect(val);

	val = pf_dep_cfg_get_val(RT2860_NVRAM, WLAN_AP1_HT_EXTCHA, DEFAULT_WLAN_24G_AP_HT_EXTCHA);
	linkcfg.ht_extcha = (val[0] == '1') ? eWLAN_EXT_CHANNEL_ABOVE : eWLAN_EXT_CHANNEL_BELOW;

	val = pf_dep_cfg_get_val(RT2860_NVRAM, WLAN_AP_REKEY_INTERVAL, DEFAULT_WLAN_24G_AP_REKEY_INTERVAL);
	linkcfg.rekey = (unsigned long)strtol(val, NULL, 10);

	val = pf_dep_cfg_get_val(RT2860_NVRAM, WLAN_AP_RTSTHRESHOLD, DEFAULT_WLAN_24G_AP_RTSTHRESHOLD);
	linkcfg.rtsthreshold = (unsigned long)strtol(val, NULL, 10);

	val = pf_dep_cfg_get_val(RT2860_NVRAM, WLAN_AP_FRAGTHRESHOLD, DEFAULT_WLAN_24G_AP_FRAGTHRESHOLD);
	linkcfg.fragthreshold = (unsigned long)strtol(val, NULL, 10);

	val = pf_dep_cfg_get_val(RT2860_NVRAM, WLAN_AP_DTIMPERIOD, DEFAULT_WLAN_24G_AP_DTIMPERIOD);
	linkcfg.dtimperiod = strtol(val, NULL, 10);

	val = pf_dep_cfg_get_val(RT2860_NVRAM, WLAN_AP_TXBURST, DEFAULT_WLAN_24G_AP_TXBURST);
	linkcfg.txburst = (val[0] == '1') ? eBOOL_TRUE : eBOOL_FALSE;

	val = pf_dep_cfg_get_val(RT2860_NVRAM, WLAN_AP_PKTAGGREGATE, DEFAULT_WLAN_24G_AP_PKTAGGREGATE);
	linkcfg.pktaggregate = (val[0] == '1') ? eBOOL_TRUE : eBOOL_FALSE;

	val = pf_dep_cfg_get_val(RT2860_NVRAM, WLAN_AP_GREENAP, DEFAULT_WLAN_24G_AP_GREENAP);
	linkcfg.greenap = (val[0] == '1') ? eBOOL_TRUE : eBOOL_FALSE;

	val = pf_dep_cfg_get_val(RT2860_NVRAM, WLAN_AP1_GREENFIELD, DEFAULT_WLAN_24G_AP_GREENFIELD);
	linkcfg.greenfield = (val[0] == '1') ? eBOOL_TRUE : eBOOL_FALSE;

	val = pf_dep_cfg_get_val(RT2860_NVRAM, WLAN_AP_RADIOON, DEFAULT_WLAN_24G_AP_RADIOON);
	linkcfg.radio_on = (val[0] == '1') ? eBOOL_TRUE : eBOOL_FALSE;
	mask_set_bit(mask.mask[0], eWLAN_AP_IF_LINKCFG_MASK0_APENABLE);

	val = pf_dep_cfg_get_val(RT2860_NVRAM, WLAN_WSC_ENABLE, DEFAULT_WLAN_24G_AP_WSC_ENABLE);
	linkcfg.wps_enable = (val[0] == '1') ? eBOOL_TRUE : eBOOL_FALSE;

	val = pf_dep_cfg_get_val(RT2860_NVRAM, WLAN_WSC_CONFIGED, DEFAULT_WLAN_24G_AP_WSC_CONFIGED);
	linkcfg.wps_configed = (val[0] == '1') ? eBOOL_TRUE : eBOOL_FALSE;

	val = pf_dep_cfg_get_val(RT2860_NVRAM, WLAN_WSC_VENDOR_PIN_CODE, "");
	linkcfg.wps_pin = strtol(val, NULL, 10);

	ret = dp_if_do_cmd(&wlan24g_ap, eDP_IF_METHOD_SET_LINKCFG, &linkcfg, &mask, NULL);
	if (ret != eRET_SUCCESS) {
		sysmgr_err("dp_if_do_cmd(%s, eDP_IF_METHOD_SET_LINKCFG) "
			   "failed[0x%08lX][0x%08lX], ret: %d\n", wlan24g_ap.name, mask.mask[0], mask.mask[1], ret);
		return (ret);
	}

	ret = dp_if_add_bridge_member(wlan24g_ap.name);
	if (ret != eRET_SUCCESS) {
		sysmgr_err("dp_if_add_bridge_member() failed, ret: %d\n", ret);
	}

	return (ret);

}

e_ret init_wlan5g_ap_if(tdata_paths * dp)
{

	int i;
	e_ret ret;
	tmask mask;
	const char *val;
	const char *append_val;
	char *item, *item_p, acl_str[1024];
	twlan_ap_if_linkcfg linkcfg;

	memset(&linkcfg, 0, sizeof(linkcfg));
	memset(&mask, 0, sizeof(mask));

	/* Set LOAD CONFIG BIT */
	mask_set_bit(mask.mask[7], eDP_IF_LINKCFG_MASK7_LOAD_CFG);

	val = pf_dep_cfg_get_val(RTDEV_NVRAM, WLAN_AP1_SSID_KEY, DEFAULT_WLAN_5G_AP_SSID);
	str_safe_cpy(linkcfg.ssid, val, WLAN_SSID_SIZE - 1);
	mask_set_bit(mask.mask[0], eWLAN_AP_IF_LINKCFG_MASK0_SSID);

	val = pf_dep_cfg_get_val(RTDEV_NVRAM, WLAN_AP_WL_MODE_KEY, DEFAULT_WLAN_5G_AP_WL_MODE);
	linkcfg.mode = pd_dep_wlmode_to_wlmode_5g(val);

	val = pf_dep_cfg_get_val(RTDEV_NVRAM, WLAN_AP_HTBW_CFG_KEY, DEFAULT_WLAN_5G_AP_HTBW);
	append_val = pf_dep_cfg_get_val(RTDEV_NVRAM, WLAN_AP_VHTBW_CFG_KEY, DEFAULT_WLAN_5G_AP_VHTBW);
	linkcfg.bw = pd_dep_bw_to_bw(val, append_val);

	val = pf_dep_cfg_get_val(RTDEV_NVRAM, WLAN_AP_SGI_CFG_KEY, DEFAULT_WLAN_5G_AP_HTGI);
	linkcfg.sgi = (val[0] == '1') ? eBOOL_TRUE : eBOOL_FALSE;

	val = pf_dep_cfg_get_val(RTDEV_NVRAM, WLAN_AP_TXPOWER_KEY, DEFAULT_WLAN_5G_AP_TXPOWER);
	linkcfg.tx_pwr = strtol(val, NULL, 10);

	val = pf_dep_cfg_get_val(RTDEV_NVRAM, WLAN_AP_CHANNEL_KEY, DEFAULT_WLAN_5G_AP_CHANNEL);
	append_val = pf_dep_cfg_get_val(RTDEV_NVRAM, WLAN_AP_AUTO_CH_SEL_KEY, DEFAULT_WLAN_5G_AP_AUTO_CHANNEL);
	if ((val[0] == '0') || (append_val[0] == '1')) {
		linkcfg.channel = 0;
	} else {
		linkcfg.channel = strtol(val, NULL, 10);
	}

	val = pf_dep_cfg_get_val(RTDEV_NVRAM, WLAN_AP_BEACON_PERIOD_KEY, DEFAULT_WLAN_5G_AP_BEACON_PERIOD);
	linkcfg.beacon_interval = strtol(val, NULL, 10);

	val = pf_dep_cfg_get_val(RTDEV_NVRAM, WLAN_AP_HIDE_SSID_KEY, DEFAULT_WLAN_5G_AP_HIDE_SSID);
	linkcfg.hide_ssid = (val[0] == '1') ? eBOOL_TRUE : eBOOL_FALSE;

	val = pf_dep_cfg_get_val(RTDEV_NVRAM, WLAN_AP_STA_ISOLATE_KEY, DEFAULT_WLAN_5G_AP_STA_ISOLATE);
	linkcfg.sta_isolate = (val[0] == '1') ? eBOOL_TRUE : eBOOL_FALSE;;

	val = pf_dep_cfg_get_val(RTDEV_NVRAM, WLAN_AP_AUTH_MODE_KEY, DEFAULT_WLAN_5G_AP_AUTH_MODE);
	append_val = pf_dep_cfg_get_val(RTDEV_NVRAM, WLAN_AP_ENC_WPA_MIX_KEY, DEFAULT_WLAN_5G_AP_ENC_WPAMIX);
	if (append_val[0] != '\0') {
		linkcfg.auth_mode = eWLAN_AUTH_MODE_WPAPSKWPA2PSK;
	} else {
		linkcfg.auth_mode = pd_dep_authmode_to_authmode(val);
	}

	val = pf_dep_cfg_get_val(RTDEV_NVRAM, WLAN_AP_ENC_TYPE_KEY, DEFAULT_WLAN_5G_AP_ENC_TYPE);
	append_val = pf_dep_cfg_get_val(RTDEV_NVRAM, WLAN_AP_ENC_WPA_MIX_KEY, DEFAULT_WLAN_5G_AP_ENC_WPAMIX);
	linkcfg.enc_method = pd_dep_enctype_to_enctype(linkcfg.auth_mode, val, append_val);;

	if (linkcfg.enc_method == eWLAN_ENC_METHOD_NONE) {
		linkcfg.sec_key.wpa_psk[0] = 0;
	} else if (linkcfg.enc_method == eWLAN_ENC_METHOD_WEP) {
		/* Read WEP Key. */
		val = pf_dep_cfg_get_val(RTDEV_NVRAM, WLAN_AP1_ENC_WEP_KEY1_STR_KEY, DEFAULT_WLAN_5G_AP_KEY_STR);
		str_safe_cpy(linkcfg.sec_key.wep_key.key[0].value, val, WLAN_ENC_WEP_KEY_MAX_SIZE - 1);

		val = pf_dep_cfg_get_val(RTDEV_NVRAM, WLAN_AP1_ENC_WEP_KEY2_STR_KEY, DEFAULT_WLAN_5G_AP_KEY_STR);
		str_safe_cpy(linkcfg.sec_key.wep_key.key[1].value, val, WLAN_ENC_WEP_KEY_MAX_SIZE - 1);

		val = pf_dep_cfg_get_val(RTDEV_NVRAM, WLAN_AP1_ENC_WEP_KEY3_STR_KEY, DEFAULT_WLAN_5G_AP_KEY_STR);
		str_safe_cpy(linkcfg.sec_key.wep_key.key[2].value, val, WLAN_ENC_WEP_KEY_MAX_SIZE - 1);

		val = pf_dep_cfg_get_val(RTDEV_NVRAM, WLAN_AP1_ENC_WEP_KEY4_STR_KEY, DEFAULT_WLAN_5G_AP_KEY_STR);
		str_safe_cpy(linkcfg.sec_key.wep_key.key[3].value, val, WLAN_ENC_WEP_KEY_MAX_SIZE - 1);

		val = pf_dep_cfg_get_val(RTDEV_NVRAM, WLAN_AP_ENC_WEP_DEFAULT_KEY_ID_KEY, DEFAULT_WLAN_5G_AP_KEY_ID);
		linkcfg.sec_key.wep_key.default_id = strtol(val, NULL, 10);
		if ((linkcfg.sec_key.wep_key.default_id == 0) || (linkcfg.sec_key.wep_key.default_id > 4)) {
			linkcfg.sec_key.wep_key.default_id = 1;
		}
	} else {
		/* Read WPA PSK. */
		val = pf_dep_cfg_get_val(RTDEV_NVRAM, WLAN_AP1_ENC_WPAPSK_KEY, DEFAULT_WLAN_5G_AP_WPAPSK);
		str_safe_cpy(linkcfg.sec_key.wpa_psk, val, WLAN_ENC_WPA_PSK_MAX_SIZE - 1);
	}

	val = pf_dep_cfg_get_val(RTDEV_NVRAM, WLAN_AP1_ACCESS_POLICY_KEY, DEFAULT_WLAN_5G_AP_ACL_TYPE);
	linkcfg.acl.acl_type = strtol(val, NULL, 10);

	val = pf_dep_cfg_get_val(RTDEV_NVRAM, WLAN_AP1_ACL_STRING_KEY, DEFAULT_WLAN_5G_AP_ACL_STR);
	strcpy(acl_str, val);
	item = strtok_r(acl_str, ";", &item_p);
	i = 0;
	while (item != NULL) {
		strcpy(linkcfg.acl.acl[i++].mac, item);
		item = strtok_r(NULL, ";", &item_p);
	}
	linkcfg.acl.counter = i;

	val = pf_dep_cfg_get_val(RTDEV_NVRAM, WLAN_AP_APSD_CAPABLE, DEFAULT_WLAN_5G_AP_APSD_CAPABLE);
	linkcfg.wmm_apsd = (val[0] == '1') ? eBOOL_TRUE : eBOOL_FALSE;
	val = pf_dep_cfg_get_val(RTDEV_NVRAM, WLAN_AP_DLS_CAPABLE, DEFAULT_WLAN_5G_AP_DLS_CAPABLE);
	linkcfg.wmm_dls = (val[0] == '1') ? eBOOL_TRUE : eBOOL_FALSE;

	val = pf_dep_cfg_get_val(RTDEV_NVRAM, WLAN_AP_BG_PROTECTION, DEFAULT_WLAN_5G_AP_BG_PROTECTION);
	linkcfg.bg_protection = pd_dep_bgprotect_to_bgprotect(val);

	val = pf_dep_cfg_get_val(RTDEV_NVRAM, WLAN_AP1_HT_EXTCHA, DEFAULT_WLAN_5G_AP_HT_EXTCHA);
	linkcfg.ht_extcha = (val[0] == '1') ? eWLAN_EXT_CHANNEL_ABOVE : eWLAN_EXT_CHANNEL_BELOW;

	val = pf_dep_cfg_get_val(RTDEV_NVRAM, WLAN_AP_REKEY_INTERVAL, DEFAULT_WLAN_5G_AP_REKEY_INTERVAL);
	linkcfg.rekey = strtol(val, NULL, 10);

	val = pf_dep_cfg_get_val(RTDEV_NVRAM, WLAN_AP_RTSTHRESHOLD, DEFAULT_WLAN_5G_AP_RTSTHRESHOLD);
	linkcfg.rtsthreshold = (unsigned long)strtol(val, NULL, 10);

	val = pf_dep_cfg_get_val(RTDEV_NVRAM, WLAN_AP_FRAGTHRESHOLD, DEFAULT_WLAN_5G_AP_FRAGTHRESHOLD);
	linkcfg.fragthreshold = (unsigned long)strtol(val, NULL, 10);

	val = pf_dep_cfg_get_val(RTDEV_NVRAM, WLAN_AP_DTIMPERIOD, DEFAULT_WLAN_5G_AP_DTIMPERIOD);
	linkcfg.dtimperiod = strtol(val, NULL, 10);

	val = pf_dep_cfg_get_val(RTDEV_NVRAM, WLAN_AP_TXBURST, DEFAULT_WLAN_5G_AP_TXBURST);
	linkcfg.txburst = (val[0] == '1') ? eBOOL_TRUE : eBOOL_FALSE;

	val = pf_dep_cfg_get_val(RTDEV_NVRAM, WLAN_AP_PKTAGGREGATE, DEFAULT_WLAN_5G_AP_PKTAGGREGATE);
	linkcfg.pktaggregate = (val[0] == '1') ? eBOOL_TRUE : eBOOL_FALSE;

	val = pf_dep_cfg_get_val(RTDEV_NVRAM, WLAN_AP_GREENAP, DEFAULT_WLAN_5G_AP_GREENAP);
	linkcfg.greenap = (val[0] == '1') ? eBOOL_TRUE : eBOOL_FALSE;

	val = pf_dep_cfg_get_val(RTDEV_NVRAM, WLAN_AP1_GREENFIELD, DEFAULT_WLAN_5G_AP_GREENFIELD);
	linkcfg.greenfield = (val[0] == '1') ? eBOOL_TRUE : eBOOL_FALSE;

	val = pf_dep_cfg_get_val(RTDEV_NVRAM, WLAN_AP_RADIOON, DEFAULT_WLAN_5G_AP_RADIOON);
	linkcfg.radio_on = (val[0] == '1') ? eBOOL_TRUE : eBOOL_FALSE;

	val = pf_dep_cfg_get_val(RTDEV_NVRAM, WLAN_WSC_ENABLE, DEFAULT_WLAN_5G_AP_WSC_ENABLE);
	linkcfg.wps_enable = (val[0] == '1') ? eBOOL_TRUE : eBOOL_FALSE;

	val = pf_dep_cfg_get_val(RTDEV_NVRAM, WLAN_WSC_CONFIGED, DEFAULT_WLAN_5G_AP_WSC_CONFIGED);
	linkcfg.wps_configed = (val[0] == '1') ? eBOOL_TRUE : eBOOL_FALSE;

	val = pf_dep_cfg_get_val(RTDEV_NVRAM, WLAN_WSC_VENDOR_PIN_CODE, "");
	linkcfg.wps_pin = strtol(val, NULL, 10);

	ret = dp_if_do_cmd(&wlan5g_ap, eDP_IF_METHOD_SET_LINKCFG, &linkcfg, &mask, NULL);
	if (ret != eRET_SUCCESS) {
		sysmgr_err("dp_if_do_cmd(%s, eDP_IF_METHOD_SET_LINKCFG) "
			   "failed[0x%08lX][0x%08lX], ret: %d\n", wlan5g_ap.name, mask.mask[0], mask.mask[1], ret);
	}

	ret = dp_if_add_bridge_member(wlan5g_ap.name);
	if (ret != eRET_SUCCESS) {
		sysmgr_err("dp_if_add_bridge_member() failed, ret: %d\n", ret);
	}

	return (ret);

}

e_ret init_wlan24g_cli_if(tdata_paths * dp)
{
	e_ret ret;
	tmask mask;
	const char *val;
	twlan_cli_if_linkcfg linkcfg;

	memset(&linkcfg, 0, sizeof(linkcfg));
	memset(&mask, 0, sizeof(mask));

	val = pf_dep_cfg_get_val(RT2860_NVRAM, WLAN_CLI_ENABLE_KEY, DEFAULT_WLAN_24G_CLI_ENABLE);
	if (val[0] == '1') {
		linkcfg.enable = eBOOL_TRUE;
	} else {
		linkcfg.enable = eBOOL_FALSE;
	}
	/* Set LOAD CONFIG BIT */
	mask_set_bit(mask.mask[7], eDP_IF_LINKCFG_MASK7_LOAD_CFG);

	val = pf_dep_cfg_get_val(RT2860_NVRAM, WLAN_CLI_SSID_KEY, DEFAULT_WLAN_24G_CLI_SSID);
	str_safe_cpy(linkcfg.ssid, val, WLAN_SSID_SIZE - 1);
	mask_set_bit(mask.mask[0], eWLAN_CLI_IF_LINKCFG_MASK0_SSID);

	val = pf_dep_cfg_get_val(RT2860_NVRAM, WLAN_CLI_AUTH_MODE_KEY, DEFAULT_WLAN_24G_CLI_AUTH_MODE);
	linkcfg.auth_mode = pd_dep_authmode_to_authmode(val);
	mask_set_bit(mask.mask[0], eWLAN_CLI_IF_LINKCFG_MASK0_AUTH_MODE);

	val = pf_dep_cfg_get_val(RT2860_NVRAM, WLAN_CLI_ENC_TYPE_KEY, DEFAULT_WLAN_24G_CLI_ENC_TYPE);
	linkcfg.enc_method = pd_dep_enctype_to_enctype(linkcfg.auth_mode, val, "");;
	mask_set_bit(mask.mask[0], eWLAN_CLI_IF_LINKCFG_MASK0_ENC_METHOD);

	val = pf_dep_cfg_get_val(RT2860_NVRAM, WLAN_AP_CHANNEL_KEY, DEFAULT_WLAN_24G_AP_CHANNEL);
	linkcfg.channel = strtol(val, NULL, 10);

	if (linkcfg.enc_method == eWLAN_ENC_METHOD_NONE) {
		linkcfg.sec_key.wpa_psk[0] = 0;
	} else if (linkcfg.enc_method == eWLAN_ENC_METHOD_WEP) {
		/* Read WEP Key. */
		val = pf_dep_cfg_get_val(RT2860_NVRAM, WLAN_CLI_ENC_WEP_KEY1_STR_KEY, DEFAULT_WLAN_24G_CLI_KEY_STR);
		str_safe_cpy(linkcfg.sec_key.wep_key.key[0].value, val, WLAN_ENC_WEP_KEY_MAX_SIZE - 1);

		val = pf_dep_cfg_get_val(RT2860_NVRAM, WLAN_CLI_ENC_WEP_KEY2_STR_KEY, DEFAULT_WLAN_24G_CLI_KEY_STR);
		str_safe_cpy(linkcfg.sec_key.wep_key.key[1].value, val, WLAN_ENC_WEP_KEY_MAX_SIZE - 1);

		val = pf_dep_cfg_get_val(RT2860_NVRAM, WLAN_CLI_ENC_WEP_KEY3_STR_KEY, DEFAULT_WLAN_24G_CLI_KEY_STR);
		str_safe_cpy(linkcfg.sec_key.wep_key.key[2].value, val, WLAN_ENC_WEP_KEY_MAX_SIZE - 1);

		val = pf_dep_cfg_get_val(RT2860_NVRAM, WLAN_CLI_ENC_WEP_KEY4_STR_KEY, DEFAULT_WLAN_24G_CLI_KEY_STR);
		str_safe_cpy(linkcfg.sec_key.wep_key.key[3].value, val, WLAN_ENC_WEP_KEY_MAX_SIZE - 1);

		val =
		    pf_dep_cfg_get_val(RT2860_NVRAM, WLAN_CLI_ENC_WEP_DEFAULT_KEY_ID_KEY, DEFAULT_WLAN_24G_CLI_KEY_ID);
		linkcfg.sec_key.wep_key.default_id = strtol(val, NULL, 10);
		if ((linkcfg.sec_key.wep_key.default_id == 0) || (linkcfg.sec_key.wep_key.default_id > 4)) {
			linkcfg.sec_key.wep_key.default_id = 1;
		}
	} else {
		/* Read WPA PSK. */
		val = pf_dep_cfg_get_val(RT2860_NVRAM, WLAN_CLI_ENC_WPAPSK_KEY, DEFAULT_WLAN_24G_CLI_WPAPSK);
		str_safe_cpy(linkcfg.sec_key.wpa_psk, val, WLAN_ENC_WPA_PSK_MAX_SIZE - 1);
	}
	mask_set_bit(mask.mask[0], eWLAN_CLI_IF_LINKCFG_MASK0_SEC_KEY);

	ret = dp_if_do_cmd(&wlan24g_cli, eDP_IF_METHOD_SET_LINKCFG, &linkcfg, &mask, NULL);
	if (ret != eRET_SUCCESS) {
		sysmgr_err("dp_if_do_cmd(%s, eDP_IF_METHOD_SET_LINKCFG) "
			   "failed[0x%08lX][0x%08lX], ret: %d\n", wlan24g_cli.name, mask.mask[0], mask.mask[1], ret);
		return (ret);
	}

	return (ret);

}

e_ret init_wlan5g_cli_if(tdata_paths * dp)
{

	e_ret ret;
	tmask mask;
	const char *val;
	twlan_cli_if_linkcfg linkcfg;

	memset(&linkcfg, 0, sizeof(linkcfg));
	memset(&mask, 0, sizeof(mask));

	val = pf_dep_cfg_get_val(RTDEV_NVRAM, WLAN_CLI_ENABLE_KEY, DEFAULT_WLAN_5G_CLI_ENABLE);
	if (val[0] == '1') {
		linkcfg.enable = eBOOL_TRUE;
	} else {
		linkcfg.enable = eBOOL_FALSE;
	}
	/* Set LOAD CONFIG BIT */
	mask_set_bit(mask.mask[7], eDP_IF_LINKCFG_MASK7_LOAD_CFG);

	val = pf_dep_cfg_get_val(RTDEV_NVRAM, WLAN_CLI_SSID_KEY, DEFAULT_WLAN_5G_CLI_SSID);
	str_safe_cpy(linkcfg.ssid, val, WLAN_SSID_SIZE - 1);
	mask_set_bit(mask.mask[0], eWLAN_CLI_IF_LINKCFG_MASK0_SSID);

	val = pf_dep_cfg_get_val(RTDEV_NVRAM, WLAN_CLI_AUTH_MODE_KEY, DEFAULT_WLAN_5G_CLI_AUTH_MODE);
	linkcfg.auth_mode = pd_dep_authmode_to_authmode(val);
	mask_set_bit(mask.mask[0], eWLAN_CLI_IF_LINKCFG_MASK0_AUTH_MODE);

	val = pf_dep_cfg_get_val(RTDEV_NVRAM, WLAN_CLI_ENC_TYPE_KEY, DEFAULT_WLAN_5G_CLI_ENC_TYPE);
	linkcfg.enc_method = pd_dep_enctype_to_enctype(linkcfg.auth_mode, val, "");;
	mask_set_bit(mask.mask[0], eWLAN_CLI_IF_LINKCFG_MASK0_ENC_METHOD);

	val = pf_dep_cfg_get_val(RTDEV_NVRAM, WLAN_AP_CHANNEL_KEY, DEFAULT_WLAN_5G_AP_CHANNEL);
	linkcfg.channel = strtol(val, NULL, 10);

	if (linkcfg.enc_method == eWLAN_ENC_METHOD_NONE) {
		linkcfg.sec_key.wpa_psk[0] = 0;
	} else if (linkcfg.enc_method == eWLAN_ENC_METHOD_WEP) {
		/* Read WEP Key. */
		val = pf_dep_cfg_get_val(RTDEV_NVRAM, WLAN_CLI_ENC_WEP_KEY1_STR_KEY, DEFAULT_WLAN_5G_CLI_KEY_STR);
		str_safe_cpy(linkcfg.sec_key.wep_key.key[0].value, val, WLAN_ENC_WEP_KEY_MAX_SIZE - 1);

		val = pf_dep_cfg_get_val(RTDEV_NVRAM, WLAN_CLI_ENC_WEP_KEY2_STR_KEY, DEFAULT_WLAN_5G_CLI_KEY_STR);
		str_safe_cpy(linkcfg.sec_key.wep_key.key[1].value, val, WLAN_ENC_WEP_KEY_MAX_SIZE - 1);

		val = pf_dep_cfg_get_val(RTDEV_NVRAM, WLAN_CLI_ENC_WEP_KEY3_STR_KEY, DEFAULT_WLAN_5G_CLI_KEY_STR);
		str_safe_cpy(linkcfg.sec_key.wep_key.key[2].value, val, WLAN_ENC_WEP_KEY_MAX_SIZE - 1);

		val = pf_dep_cfg_get_val(RTDEV_NVRAM, WLAN_CLI_ENC_WEP_KEY4_STR_KEY, DEFAULT_WLAN_5G_CLI_KEY_STR);
		str_safe_cpy(linkcfg.sec_key.wep_key.key[3].value, val, WLAN_ENC_WEP_KEY_MAX_SIZE - 1);

		val = pf_dep_cfg_get_val(RTDEV_NVRAM, WLAN_CLI_ENC_WEP_DEFAULT_KEY_ID_KEY, DEFAULT_WLAN_5G_CLI_KEY_ID);
		linkcfg.sec_key.wep_key.default_id = strtol(val, NULL, 10);
		if ((linkcfg.sec_key.wep_key.default_id == 0) || (linkcfg.sec_key.wep_key.default_id > 4)) {
			linkcfg.sec_key.wep_key.default_id = 1;
		}
	} else {
		/* Read WPA PSK. */
		val = pf_dep_cfg_get_val(RTDEV_NVRAM, WLAN_CLI_ENC_WPAPSK_KEY, DEFAULT_WLAN_5G_CLI_WPAPSK);
		str_safe_cpy(linkcfg.sec_key.wpa_psk, val, WLAN_ENC_WPA_PSK_MAX_SIZE - 1);
	}
	mask_set_bit(mask.mask[0], eWLAN_CLI_IF_LINKCFG_MASK0_SEC_KEY);

	ret = dp_if_do_cmd(&wlan5g_cli, eDP_IF_METHOD_SET_LINKCFG, &linkcfg, &mask, NULL);
	if (ret != eRET_SUCCESS) {
		sysmgr_err("dp_if_do_cmd(%s, eDP_IF_METHOD_SET_LINKCFG) "
			   "failed[0x%08lX][0x%08lX], ret: %d\n", wlan5g_cli.name, mask.mask[0], mask.mask[1], ret);
		return (ret);
	}

	return (ret);

}

e_ret init_eth2_if(tdata_paths * dp)
{

	e_ret ret;
	tmask mask;
	teth_if_linkcfg linkcfg;

	memset(&linkcfg, 0, sizeof(linkcfg));
	memset(&mask, 0, sizeof(mask));

	linkcfg.dumplex = eETH_IF_LINK_DUMPLEX_AUTO;
	mask_set_bit(mask.mask[0], eETH_IF_LISTCFG_MASK0_DUMPLEX);

	linkcfg.dumplex = eETH_IF_LINK_SPEED_AUTO;
	mask_set_bit(mask.mask[0], eETH_IF_LISTCFG_MASK0_SPEED);

	ret = dp_if_do_cmd(&eth2, eDP_IF_METHOD_SET_LINKCFG, &linkcfg, &mask, NULL);
	if (ret != eRET_SUCCESS) {
		sysmgr_err("dp_if_do_cmd(%s, eDP_IF_METHOD_SET_LINKCFG) "
			   "failed[0x%08lX][0x%08lX], ret: %d\n", eth2.name, mask.mask[0], mask.mask[1], ret);
	}

	return (ret);

}

e_ret init_eth2_vid1_if(tdata_paths * dp)
{

	e_ret ret;
	tmask mask;
	tvlan_if_linkcfg linkcfg;

	memset(&linkcfg, 0, sizeof(linkcfg));
	memset(&mask, 0, sizeof(mask));

	str_safe_cpy(linkcfg.base_if, "eth2", DP_IF_NAMESIZE - 1);
	mask_set_bit(mask.mask[0], eVLAN_IF_LINKCFG_MASK0_BASEIF);

	linkcfg.vlan_id = 1;
	mask_set_bit(mask.mask[0], eVLAN_IF_LINKCFG_MASK0_VLANID);

	ret = dp_if_do_cmd(&eth2_vid1, eDP_IF_METHOD_SET_LINKCFG, &linkcfg, &mask, NULL);
	if (ret != eRET_SUCCESS) {
		sysmgr_err("dp_if_do_cmd(%s, eDP_IF_METHOD_SET_LINKCFG) "
			   "failed[0x%08lX][0x%08lX], ret: %d\n", eth2_vid1.name, mask.mask[0], mask.mask[1], ret);
	}

	return (ret);

}

e_ret init_eth2_vid2_if(tdata_paths * dp)
{

	e_ret ret;
	tmask mask;
	tvlan_if_linkcfg linkcfg;

	memset(&linkcfg, 0, sizeof(linkcfg));
	memset(&mask, 0, sizeof(mask));

	str_safe_cpy(linkcfg.base_if, "eth2", DP_IF_NAMESIZE - 1);
	mask_set_bit(mask.mask[0], eVLAN_IF_LINKCFG_MASK0_BASEIF);

	linkcfg.vlan_id = 2;
	mask_set_bit(mask.mask[0], eVLAN_IF_LINKCFG_MASK0_VLANID);

	ret = dp_if_do_cmd(&eth2_vid2, eDP_IF_METHOD_SET_LINKCFG, &linkcfg, &mask, NULL);
	if (ret != eRET_SUCCESS) {
		sysmgr_err("dp_if_do_cmd(%s, eDP_IF_METHOD_SET_LINKCFG) "
			   "failed[0x%08lX][0x%08lX], ret: %d\n", eth2_vid2.name, mask.mask[0], mask.mask[1], ret);
		return (ret);
	}

	ret |= dp_if_add_bridge_member(eth2_vid2.name);
	if (ret != eRET_SUCCESS) {
		sysmgr_err("dp_if_add_bridge_member() failed, ret: %d\n", ret);
	}

	return (ret);

}

e_ret init_lan_br_if_link(tdata_paths * dp)
{

	e_ret ret;
	tmask mask;
	tbridge_if_linkcfg linkcfg;

	/* Disable AP Client Link */
	pf_dep_wlancli_set_linkenable(&wlan24g_cli, eBOOL_FALSE, eBOOL_FALSE);
	pf_dep_wlancli_set_linkenable(&wlan5g_cli, eBOOL_FALSE, eBOOL_FALSE);
	/* Clean up not constant interface */
	os_dep_del_bridge_member(&lan_bridge, &wlan24g_cli);
	os_dep_del_bridge_member(&lan_bridge, &wlan5g_cli);
#ifndef APCLI_BOND_SUPPORT
	/* Set Link down */
	os_dep_if_down(wlan24g_cli.name);
	os_dep_if_down(wlan5g_cli.name);
#endif /* APCLI_BOND_SUPPORT */

	memset(&linkcfg, 0, sizeof(linkcfg));
	memset(&mask, 0, sizeof(mask));

	mask_set_bit(mask.mask[0], eBRIDGE_IF_LINKCFG_MASK0_MEMBERS);

	ret = dp_if_do_cmd(&lan_bridge, eDP_IF_METHOD_SET_LINKCFG, &linkcfg, &mask, NULL);
	if (ret != eRET_SUCCESS) {
		sysmgr_err("dp_if_do_cmd(%s, eDP_IF_METHOD_SET_LINKCFG) "
			   "failed[0x%08lX][0x%08lX], ret: %d\n", lan_bridge.name, mask.mask[0], mask.mask[1], ret);
		return (ret);
	}

	return (ret);

}

e_ret init_lan_br_if_qis_net(e_bool done)
{

	e_ret ret;
	tmask mask;
	tdp_if_netcfg netcfg;
	tdata_paths *dp = lan_bridge.data_paths;
	memset(&netcfg, 0, sizeof(netcfg));
	memset(&mask, 0, sizeof(mask));

	if ((dp != NULL) && (dp->mode == eDP_MODE_BRIDGE_REPEATER)) {
		if (done == eBOOL_FALSE) {
			/* Static Network config. and Enable DHCPD */
			netcfg.conntype = eDP_IF_CONN_TYPE_STATIC;
			mask_set_bit(mask.mask[0], eDP_IF_NETCFG_MASK0_CONNTYPE);

			strcpy(netcfg.static_conn.ipaddr, DEFAULT_LAN_STATIC_IP);
			mask_set_bit(mask.mask[1], eDP_IF_NETCFG_MASK1_STATIC_IPADDR);

			strcpy(netcfg.static_conn.netmask, DEFAULT_LAN_STATIC_MASK);
			mask_set_bit(mask.mask[1], eDP_IF_NETCFG_MASK1_STATIC_NETMASK);

			strcpy(netcfg.static_conn.defaultgw, DEFAULT_LAN_STATIC_GW);
			mask_set_bit(mask.mask[1], eDP_IF_NETCFG_MASK1_STATIC_DEFAULTGW);

			netcfg.man_dns = eBOOL_TRUE;
			strcpy(netcfg.dns.dns1, DEFAULT_NETCFG_DEFAULT_DNS1);
			strcpy(netcfg.dns.dns2, DEFAULT_NETCFG_DEFAULT_DNS2);
			mask_set_bit(mask.mask[0], eDP_IF_NETCFG_MASK0_MANUAL_DNS);

			netcfg.dhcpd_cfg.dhcpd_type = eDP_IF_DHCPD_TYPE_ENABLE;

			strcpy(netcfg.dhcpd_cfg.start, DEFAULT_NETCFG_DHCPD_POOL_START);
			strcpy(netcfg.dhcpd_cfg.end, DEFAULT_NETCFG_DHCPD_POOL_END);
			strcpy(netcfg.dhcpd_cfg.netmask, DEFAULT_NETCFG_DHCPD_NETMASK);
			strcpy(netcfg.dhcpd_cfg.defaultgw, DEFAULT_NETCFG_DHCPD_DEFAULT_GW);
			netcfg.dhcpd_cfg.lease = 60;
			strcpy(netcfg.dhcpd_cfg.dns.dns1, DEFAULT_NETCFG_DHCPD_DNS1);
			strcpy(netcfg.dhcpd_cfg.dns.dns2, DEFAULT_NETCFG_DHCPD_DNS2);
			mask_set_bit(mask.mask[0], eDP_IF_NETCFG_MASK0_DHCPD);
		} else {
			/* Dynamic Network config. and Start Smart DHCPD */
			netcfg.conntype = eDP_IF_CONN_TYPE_DHCP;
			mask_set_bit(mask.mask[0], eDP_IF_NETCFG_MASK0_CONNTYPE);

			netcfg.man_dns = eBOOL_FALSE;
			strcpy(netcfg.dns.dns1, DEFAULT_NETCFG_DEFAULT_DNS1);
			strcpy(netcfg.dns.dns2, DEFAULT_NETCFG_DEFAULT_DNS2);
			mask_set_bit(mask.mask[0], eDP_IF_NETCFG_MASK0_MANUAL_DNS);

			netcfg.dhcpd_cfg.dhcpd_type = eDP_IF_DHCPD_TYPE_SMART;
			mask_set_bit(mask.mask[0], eDP_IF_NETCFG_MASK0_DHCPD);
		}
	} else {
		/* Dynamic Network config. and Start Smart DHCPD */
		netcfg.conntype = eDP_IF_CONN_TYPE_DHCP;
		mask_set_bit(mask.mask[0], eDP_IF_NETCFG_MASK0_CONNTYPE);

		netcfg.man_dns = eBOOL_FALSE;
		strcpy(netcfg.dns.dns1, DEFAULT_NETCFG_DEFAULT_DNS1);
		strcpy(netcfg.dns.dns2, DEFAULT_NETCFG_DEFAULT_DNS2);
		mask_set_bit(mask.mask[0], eDP_IF_NETCFG_MASK0_MANUAL_DNS);

		netcfg.dhcpd_cfg.dhcpd_type = eDP_IF_DHCPD_TYPE_SMART;
		mask_set_bit(mask.mask[0], eDP_IF_NETCFG_MASK0_DHCPD);
	}

	ret = dp_if_do_cmd(&lan_bridge, eDP_IF_METHOD_SET_NETCFG, &netcfg, &mask, NULL);
	if (ret != eRET_SUCCESS) {
		sysmgr_err("dp_if_do_cmd(%s, eDP_IF_METHOD_SET_NETCFG) "
			   "failed[0x%08lX][0x%08lX], ret: %d\n", lan_bridge.name, mask.mask[0], mask.mask[1], ret);
		return (ret);
	}
#if 0
	/* Disable and Enable Phy Port. */
	os_dep_do_system("mii_mgr", "-s", "-p", "4", "-r", "0", "-v", "0x3900", NULL);
	os_dep_do_system("mii_mgr", "-s", "-p", "4", "-r", "0", "-v", "0x3100", NULL);
	os_dep_do_system("mii_mgr", "-s", "-p", "4", "-r", "0", "-v", "0x3300", NULL);
#endif
	return (ret);

}

e_ret init_lan_br_if_user_cfg_net(tdata_paths * dp)
{

	e_ret ret;
	tmask mask;
	const char *val;
	char key[NVRAM_CFG_KEY_SIZE] = { 0 };
	tdp_if_netcfg netcfg;

	memset(&netcfg, 0, sizeof(netcfg));
	memset(&mask, 0, sizeof(mask));

	sprintf(key, NETCFG_CT_KEY, lan_bridge.name);
	val = pf_dep_cfg_get_val(RT2860_NVRAM, key, DEFAULT_LAN_CONNECT_TYPE);
	netcfg.conntype = pf_dep_conntype_to_conntype(val);
	mask_set_bit(mask.mask[0], eDP_IF_NETCFG_MASK0_CONNTYPE);

	switch (netcfg.conntype) {
	case eDP_IF_CONN_TYPE_PPTP:
	case eDP_IF_CONN_TYPE_PPPOE:
	case eDP_IF_CONN_TYPE_PPP:
		netcfg.conntype = eDP_IF_CONN_TYPE_DHCP;
		break;

	case eDP_IF_CONN_TYPE_DHCP:
		break;

	case eDP_IF_CONN_TYPE_STATIC:
		sprintf(key, CT_STATIC_IP_KEY, lan_bridge.name);
		val = pf_dep_cfg_get_val(RT2860_NVRAM, key, DEFAULT_LAN_STATIC_IP);
		strcpy(netcfg.static_conn.ipaddr, val);
		mask_set_bit(mask.mask[1], eDP_IF_NETCFG_MASK1_STATIC_IPADDR);

		sprintf(key, CT_STATIC_MASK_KEY, lan_bridge.name);
		val = pf_dep_cfg_get_val(RT2860_NVRAM, key, DEFAULT_LAN_STATIC_MASK);
		strcpy(netcfg.static_conn.netmask, val);
		mask_set_bit(mask.mask[1], eDP_IF_NETCFG_MASK1_STATIC_NETMASK);

		sprintf(key, CT_STATIC_GW_KEY, lan_bridge.name);
		val = pf_dep_cfg_get_val(RT2860_NVRAM, key, DEFAULT_LAN_STATIC_GW);
		strcpy(netcfg.static_conn.defaultgw, val);
		mask_set_bit(mask.mask[1], eDP_IF_NETCFG_MASK1_STATIC_DEFAULTGW);
		break;

	case eDP_IF_CONN_TYPE_NONE:
	default:
		break;
	}

	sprintf(key, NETCFG_MTU_KEY, lan_bridge.name);
	val = pf_dep_cfg_get_val(RT2860_NVRAM, key, DEFAULT_NETCFG_MTU);
	netcfg.mtu = strtol(val, NULL, 10);
	mask_set_bit(mask.mask[0], eDP_IF_NETCFG_MASK0_MTU);

	sprintf(key, NETCFG_MANUAL_DNS_KEY, lan_bridge.name);
	val = pf_dep_cfg_get_val(RT2860_NVRAM, key, DEFAULT_NETCFG_MANUAL_DNS);
	netcfg.man_dns = (val[0] == '0') ? eBOOL_FALSE : eBOOL_TRUE;

	sprintf(key, NETCFG_DNS1_KEY, lan_bridge.name);
	val = pf_dep_cfg_get_val(RT2860_NVRAM, key, DEFAULT_NETCFG_DEFAULT_DNS1);
	strcpy(netcfg.dns.dns1, val);

	sprintf(key, NETCFG_DNS2_KEY, lan_bridge.name);
	val = pf_dep_cfg_get_val(RT2860_NVRAM, key, DEFAULT_NETCFG_DEFAULT_DNS2);
	strcpy(netcfg.dns.dns2, val);
	mask_set_bit(mask.mask[0], eDP_IF_NETCFG_MASK0_MANUAL_DNS);

	sprintf(key, NETCFG_DHCPD_TYPE_KEY, lan_bridge.name);
	val = pf_dep_cfg_get_val(RT2860_NVRAM, key, DEFAULT_NETCFG_DHCPD_TYPE);
	netcfg.dhcpd_cfg.dhcpd_type = strtol(val, NULL, 10);

	sprintf(key, NETCFG_DHCPD_POOL_START_KEY, lan_bridge.name);
	val = pf_dep_cfg_get_val(RT2860_NVRAM, key, DEFAULT_NETCFG_DHCPD_POOL_START);
	strcpy(netcfg.dhcpd_cfg.start, val);

	sprintf(key, NETCFG_DHCPD_POOL_END_KEY, lan_bridge.name);
	val = pf_dep_cfg_get_val(RT2860_NVRAM, key, DEFAULT_NETCFG_DHCPD_POOL_END);
	strcpy(netcfg.dhcpd_cfg.end, val);

	sprintf(key, NETCFG_DHCPD_NETMASK_KEY, lan_bridge.name);
	val = pf_dep_cfg_get_val(RT2860_NVRAM, key, DEFAULT_NETCFG_DHCPD_NETMASK);
	strcpy(netcfg.dhcpd_cfg.netmask, val);

	sprintf(key, NETCFG_DHCPD_DEFAULT_GW_KEY, lan_bridge.name);
	val = pf_dep_cfg_get_val(RT2860_NVRAM, key, DEFAULT_NETCFG_DHCPD_DEFAULT_GW);
	strcpy(netcfg.dhcpd_cfg.defaultgw, val);

	sprintf(key, NETCFG_DHCPD_LEASE_KEY, lan_bridge.name);
	val = pf_dep_cfg_get_val(RT2860_NVRAM, key, DEFAULT_NETCFG_DHCPD_LEASE);
	netcfg.dhcpd_cfg.lease = strtol(val, NULL, 10);

	sprintf(key, NETCFG_DHCPD_DNS1_KEY, lan_bridge.name);
	val = pf_dep_cfg_get_val(RT2860_NVRAM, key, DEFAULT_NETCFG_DHCPD_DNS1);
	strcpy(netcfg.dhcpd_cfg.dns.dns1, val);

	sprintf(key, NETCFG_DHCPD_DNS2_KEY, lan_bridge.name);
	val = pf_dep_cfg_get_val(RT2860_NVRAM, key, DEFAULT_NETCFG_DHCPD_DNS2);
	strcpy(netcfg.dhcpd_cfg.dns.dns2, val);
	mask_set_bit(mask.mask[0], eDP_IF_NETCFG_MASK0_DHCPD);

	ret = dp_if_do_cmd(&lan_bridge, eDP_IF_METHOD_SET_NETCFG, &netcfg, &mask, NULL);
	if (ret != eRET_SUCCESS) {
		sysmgr_err("dp_if_do_cmd(%s, eDP_IF_METHOD_SET_NETCFG) "
			   "failed[0x%08lX][0x%08lX], ret: %d\n", lan_bridge.name, mask.mask[0], mask.mask[1], ret);
		return (ret);
	}

	return (ret);

}

e_ret init_lan_br_if_net(tdata_paths * dp)
{
	e_ret ret;
	unsigned char qis_done;

	ret = pf_dep_get_qis(&qis_done);
	if (ret != eRET_SUCCESS) {
		qis_done = eBOOL_FALSE;
		pf_dep_set_qis(qis_done);
	}

	os_dep_set_if_ipaddr(lan_bridge.name, PF_DEP_DEFAULT_IP_ADDR);
	os_dep_set_if_netmask(lan_bridge.name, PF_DEP_DEFAULT_NET_MASK);
	os_dep_change_default_gw(PF_DEP_DEFAULT_GATEWAY);
	os_dep_update_name_server("8.8.8.8", NULL);

	if (qis_done == eBOOL_TRUE) {
		ret = init_lan_br_if_user_cfg_net(dp);
	} else {
		ret = init_lan_br_if_qis_net(eBOOL_FALSE);
	}

	return (ret);
}

#ifdef APCLI_BOND_SUPPORT
e_ret dp_if_bond_member_opt(const char *if_name, unsigned char add)
{

	char cmd_buf[64];
	int rc;
	int fd;

	os_dep_if_down(if_name);

	fd = open(SYS_FS_APCLI_BOND_SLAVE, O_RDWR);
	if (fd < 0) {
		sysmgr_info("open(%s) failed, err: %d,[%s]\n", SYS_FS_APCLI_BOND_SLAVE, errno, strerror(errno));
		return eRET_FAILURE;
	}
	if (add) {
		rc = sprintf(cmd_buf, "+%s", if_name);
		cmd_buf[rc] = 0;
	} else {
		rc = sprintf(cmd_buf, "-%s", if_name);
		cmd_buf[rc] = 0;
	}

	rc = write(fd, cmd_buf, strlen(cmd_buf));
	sysmgr_dbg("write(%s, [%s]) ret: %d\n", SYS_FS_APCLI_BOND_SLAVE, cmd_buf, rc);
	if (rc < 0) {
		sysmgr_err("write(%s, [%s]) failed, ret: %d\n", SYS_FS_APCLI_BOND_SLAVE, cmd_buf, rc);
		close(fd);
		return (eRET_FAILURE);
	}

	close(fd);

	os_dep_if_up(if_name);

	return (eRET_SUCCESS);

}

e_ret init_apcli_bond_if(tdata_paths * dp)
{

	int fd;

	os_dep_do_system("insmod", OS_DEP_BONDING_DRIVER_MOD, NULL);

	fd = open(SYS_FS_BONDING_MASTER, O_RDWR);
	if (fd < 0) {
		sysmgr_info("open(%s) failed, err: %d,[%s]\n", SYS_FS_BONDING_MASTER, errno, strerror(errno));
		return eRET_FAILURE;
	}
	write(fd, "-bond0", 6);
	write(fd, "+apcli_bond", 11);
	close(fd);

	fd = open(SYS_FS_APCLI_BOND_MODE, O_RDWR);
	if (fd < 0) {
		sysmgr_info("open(%s) failed, err: %d,[%s]\n", SYS_FS_APCLI_BOND_MODE, errno, strerror(errno));
		return eRET_FAILURE;
	}
	write(fd, "6", 1);
	close(fd);

	fd = open(SYS_FS_APCLI_BOND_MIIMON, O_RDWR);
	if (fd < 0) {
		sysmgr_info("open(%s) failed, err: %d,[%s]\n", SYS_FS_APCLI_BOND_MIIMON, errno, strerror(errno));
		return eRET_FAILURE;
	}
	write(fd, "1000", 4);
	close(fd);

	os_dep_if_up(apcli_bond.name);

	return (eRET_SUCCESS);

}

e_ret add_apcli_bond_if_to_br(tdata_paths * dp)
{

	e_ret ret;
	static e_bool added = eBOOL_FALSE;


	if (!added) {
		ret = dp_if_set_bridge_uplink(apcli_bond.name);
		if (ret != eRET_SUCCESS) {
			sysmgr_err("dp_if_set_bridge_uplink() failed, ret: %d\n", ret);
			return (ret);
		}
		added = eBOOL_TRUE;
	}

	return (eRET_SUCCESS);

}

void cleanup_apcli_bond_if(tdata_paths * dp)
{
	os_dep_if_down(apcli_bond.name);
	os_dep_do_system("rmmod", OS_DEP_BONDING_DRIVER_MOD, NULL);
}

#endif /* APCLI_BOND_SUPPORT */

e_ret dp_if_set_bridge_uplink(const char *if_name)
{

	e_ret ret;
	tmask mask;
	tbridge_if_linkcfg linkcfg;

	memset(&linkcfg, 0, sizeof(linkcfg));
	memset(&mask, 0, sizeof(mask));

	str_safe_cpy(linkcfg.uplink, if_name, DP_IF_NAMESIZE - 1);
	mask_set_bit(mask.mask[0], eBRIDGE_IF_LINKCFG_MASK0_UPLINK);

	ret = dp_if_do_cmd(&lan_bridge, eDP_IF_METHOD_SET_LINKCFG, &linkcfg, &mask, NULL);
	if (ret != eRET_SUCCESS) {
		sysmgr_err("dp_if_do_cmd(%s, eDP_IF_METHOD_GET_LINKCFG) "
			   "failed[0x%08lX][0x%08lX], ret: %d\n", lan_bridge.name, mask.mask[0], mask.mask[1], ret);
		return (ret);
	}

	return (ret);

}

e_ret dp_if_add_bridge_member(const char *if_name)
{

	e_ret ret;
	tmask mask;
	int i;
	int size;
	int first_blank;
	tbridge_if_linkcfg *linkcfg;

	memset(&mask, 0, sizeof(mask));

	ret = dp_if_do_cmd(&lan_bridge, eDP_IF_METHOD_GET_LINKCFG, &linkcfg, &size, &mask, NULL);
	if (ret != eRET_SUCCESS) {
		sysmgr_err("dp_if_do_cmd(%s, eDP_IF_METHOD_GET_LINKCFG) "
			   "failed[0x%08lX][0x%08lX], ret: %d\n", lan_bridge.name, mask.mask[0], mask.mask[1], ret);
		return (ret);
	}

	first_blank = DP_BR_MEMBER_MAX;
	for (i = 0; i < DP_BR_MEMBER_MAX; i++) {
		if (linkcfg->members[i][0] == 0) {
			if (first_blank == DP_BR_MEMBER_MAX) {
				first_blank = i;
			}
		} else if (strcmp(if_name, linkcfg->members[i]) == 0) {
			ret = eRET_SUCCESS;
			goto out;
		}
	}

	if (first_blank == DP_BR_MEMBER_MAX) {
		ret = eRET_NO_RESOURCE;
		goto out;
	}

	strcpy(linkcfg->members[first_blank], if_name);
	sysmgr_dbg("first_blank: %d, member[first_blank] == [%s]\n", first_blank, linkcfg->members[first_blank]);
	mask_set_bit(mask.mask[0], eBRIDGE_IF_LINKCFG_MASK0_MEMBERS);

	ret = dp_if_do_cmd(&lan_bridge, eDP_IF_METHOD_SET_LINKCFG, linkcfg, &mask, NULL);
	if (ret != eRET_SUCCESS) {
		sysmgr_err("dp_if_do_cmd(%s, eDP_IF_METHOD_GET_LINKCFG) "
			   "failed[0x%08lX][0x%08lX], ret: %d\n", lan_bridge.name, mask.mask[0], mask.mask[1], ret);
	}

out:
	if (linkcfg != NULL) {
		free(linkcfg);
	}

	return (ret);

}

e_ret dp_if_del_bridge_member(const char *if_name)
{

	e_ret ret;
	tmask mask;
	int i;
	int size;
	tbridge_if_linkcfg *linkcfg;

	memset(&mask, 0, sizeof(mask));
	ret = dp_if_do_cmd(&lan_bridge, eDP_IF_METHOD_GET_LINKCFG, &linkcfg, &size, &mask, NULL);
	if (ret != eRET_SUCCESS) {
		sysmgr_err("dp_if_do_cmd(%s, eDP_IF_METHOD_GET_LINKCFG) "
			   "failed[0x%08lX][0x%08lX], ret: %d\n", lan_bridge.name, mask.mask[0], mask.mask[1], ret);
		return (ret);
	}

	for (i = 0; i < DP_BR_MEMBER_MAX; i++) {
		if (strcmp(if_name, linkcfg->members[i]) == 0) {
			memset(linkcfg->members[i], 0, DP_IF_NAMESIZE);
		}
	}
	mask_set_bit(mask.mask[0], eBRIDGE_IF_LINKCFG_MASK0_MEMBERS);

	ret = dp_if_do_cmd(&lan_bridge, eDP_IF_METHOD_SET_LINKCFG, &linkcfg, &mask, NULL);
	if (ret != eRET_SUCCESS) {
		sysmgr_err("dp_if_do_cmd(%s, eDP_IF_METHOD_GET_LINKCFG) "
			   "failed[0x%08lX][0x%08lX], ret: %d\n", lan_bridge.name, mask.mask[0], mask.mask[1], ret);
	}

	if (linkcfg != NULL) {
		free(linkcfg);
	}

	return (ret);

}

void cleanup_wlan24g_ap_if(tdata_paths * dp)
{
	dp_if_do_cmd(&wlan24g_ap, eDP_IF_METHOD_DESTORY, NULL);
}

void cleanup_wlan5g_ap_if(tdata_paths * dp)
{
	dp_if_do_cmd(&wlan5g_ap, eDP_IF_METHOD_DESTORY, NULL);
}

void cleanup_wlan24g_cli_if(tdata_paths * dp)
{
	dp_if_do_cmd(&wlan24g_cli, eDP_IF_METHOD_DESTORY, NULL);
}

void cleanup_wlan5g_cli_if(tdata_paths * dp)
{
	dp_if_do_cmd(&wlan5g_cli, eDP_IF_METHOD_DESTORY, NULL);
}

void cleanup_eth2_if(tdata_paths * dp)
{
	dp_if_do_cmd(&eth2, eDP_IF_METHOD_DESTORY, NULL);
}

void cleanup_eth2_vid1_if(tdata_paths * dp)
{
	dp_if_do_cmd(&eth2_vid1, eDP_IF_METHOD_DESTORY, NULL);
}

void cleanup_eth2_vid2_if(tdata_paths * dp)
{
	dp_if_do_cmd(&eth2_vid2, eDP_IF_METHOD_DESTORY, NULL);
}

void cleanup_lan_br_if(tdata_paths * dp)
{
	dp_if_do_cmd(&lan_bridge, eDP_IF_METHOD_DESTORY, NULL);
}

e_ret pf_dep_dp_ifs_init(tdata_paths * dp)
{

	int i;

	prepare_wlan_wps_cfg();

	INIT_LIST_HEAD(&dp->all_ifs);

	for (i = 0; i < SYSTEM_DATA_PATH_MAX; i++) {
		INIT_LIST_HEAD(&dp->net_ifs[i]);
	}

#ifdef APCLI_BOND_SUPPORT
	init_dp_if_list(dp, &apcli_bond, SYSTEM_DEFAULT_DP);
#endif

	init_dp_if_list(dp, &wlan5g_cli, SYSTEM_DEFAULT_DP);
	init_dp_if_list(dp, &wlan24g_cli, SYSTEM_DEFAULT_DP);
	init_dp_if_list(dp, &wlan5g_ap, SYSTEM_DEFAULT_DP);
	init_dp_if_list(dp, &wlan24g_ap, SYSTEM_DEFAULT_DP);
	init_dp_if_list(dp, &eth2_vid2, SYSTEM_DEFAULT_DP);
	init_dp_if_list(dp, &eth2_vid1, SYSTEM_DEFAULT_DP);
	init_dp_if_list(dp, &eth2, SYSTEM_DEFAULT_DP);
	init_dp_if_list(dp, &lan_bridge, SYSTEM_DEFAULT_DP);

	return (eRET_SUCCESS);
}

e_ret pf_dep_dp_rules_init(tdata_paths * dp)
{

	int i;

	for (i = 0; i < eIPT_RULE_TABLE_MAX; i++) {
		INIT_LIST_HEAD(&dp->dp_rules.ipt_rule.tables[i]);
	}

	return (eRET_SUCCESS);
}

e_ret pf_dep_dp_ifs_setup(tdata_paths * dp)
{

	e_ret ret = eRET_SUCCESS;
	char mac_addr[RC_MAC_STR_MAX_SIZE];

	pf_dep_get_device_mode(&dp->mode);

	ret |= init_lan_br_if_link(dp);

	ret |= init_eth2_if(dp);
	ret |= init_eth2_vid1_if(dp);
	ret |= init_eth2_vid2_if(dp);

	switch (dp->mode) {
	case eDP_MODE_ROUTER:
		dp_if_set_base_on_led(&wlan24g_ap, &rt_led);
		dp_if_set_base_on_led(&wlan5g_ap, &rt_led);
		mask_set_bit(wlan24g_ap.attr, eDP_IF_ATTR_LINK_WPS);
		mask_set_bit(wlan5g_ap.attr, eDP_IF_ATTR_LINK_WPS);
		ret |= init_wlan24g_ap_if(dp);
		ret |= init_wlan5g_ap_if(dp);
#ifdef APCLI_BOND_SUPPORT
		ret |= init_apcli_bond_if(dp);
#endif /* APCLI_BOND_SUPPORT */
		ret |= init_wlan24g_cli_if(dp);
		ret |= init_wlan5g_cli_if(dp);
		break;

	case eDP_MODE_BRIDGE_AP:
		dp_if_set_base_on_led(&wlan24g_ap, &rt_led);
		dp_if_set_base_on_led(&wlan5g_ap, &rt_led);
		mask_set_bit(wlan24g_ap.attr, eDP_IF_ATTR_LINK_WPS);
		mask_set_bit(wlan5g_ap.attr, eDP_IF_ATTR_LINK_WPS);
		ret |= init_wlan24g_ap_if(dp);
		ret |= init_wlan5g_ap_if(dp);
		ret |= dp_if_set_bridge_uplink(eth2_vid2.name);
		if (ret != eRET_SUCCESS) {
			sysmgr_err("dp_if_set_bridge_uplink() failed, ret: %d\n", ret);
		}
		break;

	case eDP_MODE_BRIDGE_REPEATER:
	default:
		dp_if_set_base_on_led(&wlan24g_cli, &rt_led);
		dp_if_set_base_on_led(&wlan5g_cli, &rt_led);
		mask_set_bit(wlan24g_cli.attr, eDP_IF_ATTR_LINK_WPS);
		mask_set_bit(wlan5g_cli.attr, eDP_IF_ATTR_LINK_WPS);
		ret |= init_wlan24g_ap_if(dp);
		ret |= init_wlan5g_ap_if(dp);
#ifdef APCLI_BOND_SUPPORT
		ret |= init_apcli_bond_if(dp);
#endif /* APCLI_BOND_SUPPORT */
		ret |= init_wlan24g_cli_if(dp);
		ret |= init_wlan5g_cli_if(dp);
		break;
	}

	/* Fix LAN Bridge MAC Address. */
	if (os_dep_get_if_macaddr(eth2_vid2.name, mac_addr) == eRET_SUCCESS) {
		os_dep_set_if_macaddr(lan_bridge.name, mac_addr);
		sysmgr_info("dp if[%s] set mac addr[%s], ret: %d\n", lan_bridge.name, mac_addr);
	}

	ret |= init_lan_br_if_net(dp);

	return (ret);
}

e_ret pf_dep_dp_rules_setup(tdata_paths * dp)
{
	return (eRET_SUCCESS);
}

unsigned char pd_dep_wlmode_to_wlmode_24g(const char *wlmode)
{
	unsigned char mode;
	int mode_num;
	mode_num = strtol(wlmode, NULL, 10);
	switch (mode_num) {
	case 0:
		mode = eWLAN24G_MODE_BG_MIX;
		break;
	case 1:
		mode = eWLAN24G_MODE_B_ONLY;
		break;
	case 4:
		mode = eWLAN24G_MODE_G_ONLY;
		break;
	case 6:
		mode = eWLAN24G_MODE_N_ONLY;
		break;
	case 7:
		mode = eWLAN24G_MODE_GN_MIX;
		break;
	case 9:
		mode = eWLAN24G_MODE_BGN_MIX;
		break;
	default:
		mode = eWLAN24G_MODE_AUTO;
		break;
	}

	return (mode);
}

const char *wlmode_to_pd_dep_wlmode_24g(unsigned char wlmode, char *pf_dep_wlmode)
{
	switch (wlmode) {
	case eWLAN24G_MODE_B_ONLY:
		sprintf(pf_dep_wlmode, "1");
		break;
	case eWLAN24G_MODE_G_ONLY:
		sprintf(pf_dep_wlmode, "4");
		break;
	case eWLAN24G_MODE_N_ONLY:
		sprintf(pf_dep_wlmode, "6");
		break;
	case eWLAN24G_MODE_BG_MIX:
		sprintf(pf_dep_wlmode, "0");
		break;
	case eWLAN24G_MODE_GN_MIX:
		sprintf(pf_dep_wlmode, "7");
		break;
	case eWLAN24G_MODE_BGN_MIX:
		sprintf(pf_dep_wlmode, "9");
		break;
	default:
		sprintf(pf_dep_wlmode, "7");
		break;
	}
	return (pf_dep_wlmode);
}

unsigned char pd_dep_wlmode_to_wlmode_5g(const char *wlmode)
{
	unsigned char mode;
	int mode_num;
	mode_num = strtol(wlmode, NULL, 10);
	switch (mode_num) {
	case 2:
		mode = eWLAN5G_MODE_A_ONLY;
		break;
	case 8:
		mode = eWLAN5G_MODE_AN_MIX;
		break;
	case 11:
		mode = eWLAN5G_MODE_N_ONLY;
		break;
	case 14:
		mode = eWLAN5G_MODE_ANAC_MIX;
		break;
	case 15:
		mode = eWLAN5G_MODE_NAC_MIX;
		break;
	default:
		mode = eWLAN5G_MODE_AUTO;
		break;
	}

	return (mode);
}

const char *wlmode_to_pd_dep_wlmode_5g(unsigned char wlmode, char *pf_dep_wlmode)
{
	switch (wlmode) {
	case eWLAN5G_MODE_A_ONLY:
		sprintf(pf_dep_wlmode, "2");
		break;
	case eWLAN5G_MODE_N_ONLY:
		sprintf(pf_dep_wlmode, "11");
		break;
	case eWLAN5G_MODE_AC_ONLY:
		sprintf(pf_dep_wlmode, "15");
		break;
	case eWLAN5G_MODE_AN_MIX:
		sprintf(pf_dep_wlmode, "8");
		break;
	case eWLAN5G_MODE_NAC_MIX:
		sprintf(pf_dep_wlmode, "15");
		break;
	case eWLAN5G_MODE_ANAC_MIX:
		sprintf(pf_dep_wlmode, "14");
		break;
	default:
		sprintf(pf_dep_wlmode, "15");
		break;
	}
	return (pf_dep_wlmode);
}

unsigned char pd_dep_bw_to_bw(const char *pf_dep_htbw, const char *pf_dep_vhthw)
{
	unsigned char bw;
	switch (pf_dep_vhthw[0]) {
	case '1':
		switch (pf_dep_htbw[0]) {
		case '0':
			/* Invalid ? */
			bw = eWLAN_BW_80M;
			break;

		case '1':
		default:
			bw = eWLAN_BW_20M_40M_80M;
			break;
		}
		break;

	case '0':
	default:
		switch (pf_dep_htbw[0]) {
		case '0':
			bw = eWLAN_BW_20M;
			break;

		case '1':
		default:
			bw = eWLAN_BW_20M_40M;
			break;
		}
		break;

	}

	return (bw);
}

const char *bw_to_pd_dep_bw(unsigned char bw, char *pf_dep_htbw, char *pf_dep_vhthw)
{
	switch (bw) {
	case eWLAN_BW_20M:
		pf_dep_htbw[0] = '0';
		pf_dep_htbw[1] = 0;
		pf_dep_vhthw[0] = '0';
		pf_dep_vhthw[1] = 0;
		break;

	case eWLAN_BW_20M_40M:
	case eWLAN_BW_40M:
		pf_dep_htbw[0] = '1';
		pf_dep_htbw[1] = 0;
		pf_dep_vhthw[0] = '0';
		pf_dep_vhthw[1] = 0;
		break;

	case eWLAN_BW_80M:
	case eWLAN_BW_40M_80M:
	case eWLAN_BW_20M_40M_80M:
		pf_dep_htbw[0] = '1';
		pf_dep_htbw[1] = 0;
		pf_dep_vhthw[0] = '1';
		pf_dep_vhthw[1] = 0;
		break;

	default:
		bw = eWLAN_BW_20M_40M;
	}

	return (pf_dep_htbw);

}

unsigned char pd_dep_authmode_to_authmode(const char *pf_dep_authmode)
{

	unsigned char auth_mode;

	if (strcmp(pf_dep_authmode, WLAN_AUTH_MODE_OPEN) == 0) {
		auth_mode = eWLAN_AUTH_MODE_OPEN;
	} else if (strcmp(pf_dep_authmode, WLAN_AUTH_MODE_SHARED) == 0) {
		auth_mode = eWLAN_AUTH_MODE_SHARED;
	} else if (strcmp(pf_dep_authmode, WLAN_AUTH_MODE_WEPAUTO) == 0) {
		auth_mode = eWLAN_AUTH_MODE_WEPAUTO;
	} else if (strcmp(pf_dep_authmode, WLAN_AUTH_MODE_WPAPSK) == 0) {
		auth_mode = eWLAN_AUTH_MODE_WPAPSK;
	} else if (strcmp(pf_dep_authmode, WLAN_AUTH_MODE_WPANONE) == 0) {
		auth_mode = eWLAN_AUTH_MODE_WPANONE;
	} else if (strcmp(pf_dep_authmode, WLAN_AUTH_MODE_WPA2PSK) == 0) {
		auth_mode = eWLAN_AUTH_MODE_WPA2PSK;
	} else if (strcmp(pf_dep_authmode, WLAN_AUTH_MODE_WPAPSKWPA2PSK) == 0) {
		auth_mode = eWLAN_AUTH_MODE_WPAPSKWPA2PSK;
	} else if (strcmp(pf_dep_authmode, WLAN_AUTH_MODE_WPA) == 0) {
		auth_mode = eWLAN_AUTH_MODE_WPA;
	} else if (strcmp(pf_dep_authmode, WLAN_AUTH_MODE_WPA2) == 0) {
		auth_mode = eWLAN_AUTH_MODE_WPA2;
	} else if (strcmp(pf_dep_authmode, WLAN_AUTH_MODE_WPAWPA2) == 0) {
		auth_mode = eWLAN_AUTH_MODE_WPAWPA2;
	} else {
		auth_mode = eWLAN_AUTH_MODE_OPEN;
	}

	return (auth_mode);

}

const char *authmode_to_pd_dep_authmode(unsigned char authmode, char *pf_dep_authmode)
{

	pf_dep_authmode[0] = 0;
	switch (authmode) {
	case eWLAN_AUTH_MODE_OPEN:
		strcpy(pf_dep_authmode, WLAN_AUTH_MODE_OPEN);
		break;

	case eWLAN_AUTH_MODE_SHARED:
		strcpy(pf_dep_authmode, WLAN_AUTH_MODE_SHARED);
		break;

	case eWLAN_AUTH_MODE_WEPAUTO:
		strcpy(pf_dep_authmode, WLAN_AUTH_MODE_WEPAUTO);
		break;

	case eWLAN_AUTH_MODE_WPAPSK:
		strcpy(pf_dep_authmode, WLAN_AUTH_MODE_WPAPSK);
		break;

	case eWLAN_AUTH_MODE_WPANONE:
		strcpy(pf_dep_authmode, WLAN_AUTH_MODE_WPANONE);
		break;

	case eWLAN_AUTH_MODE_WPA2PSK:
		strcpy(pf_dep_authmode, WLAN_AUTH_MODE_WPA2PSK);
		break;

	case eWLAN_AUTH_MODE_WPAPSKWPA2PSK:
		strcpy(pf_dep_authmode, WLAN_AUTH_MODE_WPAPSKWPA2PSK);
		break;

	case eWLAN_AUTH_MODE_WPA:
		strcpy(pf_dep_authmode, WLAN_AUTH_MODE_WPA);
		break;

	case eWLAN_AUTH_MODE_WPA2:
		strcpy(pf_dep_authmode, WLAN_AUTH_MODE_WPA2);
		break;
	case eWLAN_AUTH_MODE_WPAWPA2:
		strcpy(pf_dep_authmode, WLAN_AUTH_MODE_WPAWPA2);
		break;
	default:
		strcpy(pf_dep_authmode, WLAN_AUTH_MODE_OPEN);
		break;
	}

	return (pf_dep_authmode);

}

unsigned char pd_dep_enctype_to_enctype(unsigned char auth_mode,
					const char *pf_dep_enctype, const char *pf_dep_enctype_wpamix)
{

	unsigned char enc_type;

	if (auth_mode == eWLAN_AUTH_MODE_WPAPSKWPA2PSK) {
		if (strcmp(pf_dep_enctype_wpamix, WLAN_ENC_METHOD_TKIP_AES_MIX_1) == 0) {
			enc_type = eWLAN_ENC_METHOD_TKIP_AES;
		} else if (strcmp(pf_dep_enctype_wpamix, WLAN_ENC_METHOD_TKIP_AES_MIX_2) == 0) {
			enc_type = eWLAN_ENC_METHOD_TKIP_AES;
		} else if (strcmp(pf_dep_enctype_wpamix, WLAN_ENC_METHOD_TKIP_AES_MIX_3) == 0) {
			enc_type = eWLAN_ENC_METHOD_TKIP_AES;
		} else if (strcmp(pf_dep_enctype_wpamix, WLAN_ENC_METHOD_TKIP_AES_MIX_4) == 0) {
			enc_type = eWLAN_ENC_METHOD_TKIP_AES;
		} else if (strcmp(pf_dep_enctype_wpamix, WLAN_ENC_METHOD_TKIP_AES_MIX_5) == 0) {
			enc_type = eWLAN_ENC_METHOD_TKIP_AES;
		} else if (strcmp(pf_dep_enctype_wpamix, WLAN_ENC_METHOD_TKIP_AES_MIX_6) == 0) {
			enc_type = eWLAN_ENC_METHOD_TKIP_AES;
		} else if (strcmp(pf_dep_enctype_wpamix, WLAN_ENC_METHOD_TKIP_AES_MIX_7) == 0) {
			enc_type = eWLAN_ENC_METHOD_TKIP_AES;
		} else {
			enc_type = eWLAN_ENC_METHOD_TKIP_AES;
		}
	} else {
		if (strcmp(pf_dep_enctype, WLAN_ENC_METHOD_NONE) == 0) {
			enc_type = eWLAN_ENC_METHOD_NONE;
		} else if (strcmp(pf_dep_enctype, WLAN_ENC_METHOD_WEP) == 0) {
			enc_type = eWLAN_ENC_METHOD_WEP;
		} else if (strcmp(pf_dep_enctype, WLAN_ENC_METHOD_TKIP) == 0) {
			enc_type = eWLAN_ENC_METHOD_TKIP;
		} else if (strcmp(pf_dep_enctype, WLAN_ENC_METHOD_AES) == 0) {
			enc_type = eWLAN_ENC_METHOD_AES;
		} else {
			if (auth_mode == eWLAN_AUTH_MODE_OPEN) {
				enc_type = eWLAN_ENC_METHOD_AES;
			} else if ((auth_mode == eWLAN_AUTH_MODE_SHARED) || (auth_mode == eWLAN_AUTH_MODE_WEPAUTO)) {
				enc_type = eWLAN_ENC_METHOD_WEP;
			} else {
				enc_type = eWLAN_ENC_METHOD_AES;
			}
		}
	}

	return (enc_type);

}

const char *enctype_to_pd_dep_enctype(unsigned char enctype,
				      unsigned char auth_mode, char *pf_dep_enctype, char *pf_dep_enctype_wpamix)
{

	pf_dep_enctype[0] = 0;
	pf_dep_enctype_wpamix[0] = 0;

	switch (enctype) {
	case eWLAN_ENC_METHOD_NONE:
		strcpy(pf_dep_enctype, WLAN_ENC_METHOD_NONE);
		break;
	case eWLAN_ENC_METHOD_WEP:
		strcpy(pf_dep_enctype, WLAN_ENC_METHOD_WEP);
		break;
	case eWLAN_ENC_METHOD_TKIP:
		strcpy(pf_dep_enctype, WLAN_ENC_METHOD_TKIP);
		break;
	case eWLAN_ENC_METHOD_AES:
		strcpy(pf_dep_enctype, WLAN_ENC_METHOD_AES);
		break;
	case eWLAN_ENC_METHOD_TKIP_AES:
		strcpy(pf_dep_enctype, WLAN_ENC_METHOD_TKIP_AES);
		if (auth_mode == eWLAN_AUTH_MODE_WPAPSKWPA2PSK) {
			strcpy(pf_dep_enctype_wpamix, WLAN_ENC_METHOD_TKIP_AES_MIX_7);
		} else if (auth_mode == eWLAN_AUTH_MODE_OPEN) {
			strcpy(pf_dep_enctype, WLAN_ENC_METHOD_NONE);
		} else if ((auth_mode == eWLAN_AUTH_MODE_SHARED) || (auth_mode == eWLAN_AUTH_MODE_WEPAUTO)) {
			strcpy(pf_dep_enctype, WLAN_ENC_METHOD_WEP);
		} else {
			strcpy(pf_dep_enctype, WLAN_ENC_METHOD_AES);
		}
		break;
	default:
		strcpy(pf_dep_enctype, WLAN_ENC_METHOD_NONE);
		break;
	}

	return (pf_dep_enctype);

}

unsigned char pd_dep_bgprotect_to_bgprotect(const char *pf_dep_bgprotect)
{
	unsigned char bgprotect;
	int bgprotect_num;
	bgprotect_num = strtol(pf_dep_bgprotect, NULL, 10);
	switch (bgprotect_num) {
	case 0:
		bgprotect = eWLAN_BG_PROTECT_AUTO;
		break;
	case 1:
		bgprotect = eWLAN_BG_PROTECT_ON;
		break;
	case 2:
		bgprotect = eWLAN_BG_PROTECT_OFF;
		break;
	default:
		bgprotect = eWLAN_BG_PROTECT_AUTO;
		break;
	}

	return (bgprotect);
}

const char *conntype_to_pf_dep_conntype(unsigned char conntype, char *pf_dep_conntype)
{
	switch (conntype) {
	case eDP_IF_CONN_TYPE_PPTP:
		strcpy(pf_dep_conntype, CONNTYPE_VAL_PPTP);
		break;

	case eDP_IF_CONN_TYPE_PPPOE:
		strcpy(pf_dep_conntype, CONNTYPE_VAL_PPPOE);
		break;

	case eDP_IF_CONN_TYPE_PPP:
		strcpy(pf_dep_conntype, CONNTYPE_VAL_PPP);
		break;

	case eDP_IF_CONN_TYPE_DHCP:
		strcpy(pf_dep_conntype, CONNTYPE_VAL_DHCP);
		break;

	case eDP_IF_CONN_TYPE_STATIC:
		strcpy(pf_dep_conntype, CONNTYPE_VAL_STATIC);
		break;

	case eDP_IF_CONN_TYPE_NONE:
	default:
		strcpy(pf_dep_conntype, CONNTYPE_VAL_NONE);
		break;
	}
	return (pf_dep_conntype);
}

unsigned char pf_dep_conntype_to_conntype(const char *pf_dep_conntype)
{
	unsigned char conntype;

	if (strcmp(pf_dep_conntype, CONNTYPE_VAL_PPTP) == 0) {
		conntype = eDP_IF_CONN_TYPE_PPTP;
	} else if (strcmp(pf_dep_conntype, CONNTYPE_VAL_PPPOE) == 0) {
		conntype = eDP_IF_CONN_TYPE_PPPOE;
	} else if (strcmp(pf_dep_conntype, CONNTYPE_VAL_PPP) == 0) {
		conntype = eDP_IF_CONN_TYPE_PPP;
	} else if (strcmp(pf_dep_conntype, CONNTYPE_VAL_DHCP) == 0) {
		conntype = eDP_IF_CONN_TYPE_DHCP;
	} else if (strcmp(pf_dep_conntype, CONNTYPE_VAL_STATIC) == 0) {
		conntype = eDP_IF_CONN_TYPE_STATIC;
	} else if (strcmp(pf_dep_conntype, CONNTYPE_VAL_PPTP) == 0) {
		conntype = eDP_IF_CONN_TYPE_NONE;
	} else {
		conntype = eDP_IF_CONN_TYPE_NONE;
	}

	return (conntype);

}

e_ret pf_dep_get_devmac(tdevmac * devmac)
{
	os_dep_get_if_macaddr(lan_bridge.name, devmac->lan_mac);
	os_dep_get_if_macaddr(wlan24g_ap.name, devmac->wlan_24G_mac);
	os_dep_get_if_macaddr(wlan5g_ap.name, devmac->wlan_5G_mac);

	return (eRET_SUCCESS);
}
